@include('admin.public.head')
@include('admin.public.pop')

<style type="text/css">

    .inner_btn {
        background: #19a97b;
        color: white;
        padding: 5px 8px;
        border-radius: 2px;
    }

</style>

<div class="ibox-title">
    <h5>用户管理</h5>
</div>

<div class="ibox-content">
    <div class="row">
        <div class="col-sm-12 pull-right m-b-xs">
            <form action="">
                <div class="col-sm-1  m-b-xs text-center pull-right">
                    <button type="submit" class="btn btn-sm btn-primary">搜索</button>
                    <a class="btn btn-primary btn-sm dropdown-toggle"  href="/user_import" target="_blank">導出
                    </a>
                </div>

                <div class="col-sm-2 text-center pull-right">
                    <input type="text" name="sear_value" value="{{$sear_value}}" placeholder="姓名/手機號/昵稱/用戶id"
                           class="input form-control">
                </div>

            </form>
        </div>
    </div>
    <table class="table table-bordered">
        <thead>
        <tr>
            <th style="with:150px">姓名</th>
            <th>用戶編號</th>
            <th>用戶頭像</th>
            <th>用戶等级</th>
            <th>用戶昵稱</th>
            <th>手機號</th>
            <th>訓練時長(分鐘)</th>
            <th>積分</th>
            <th>礼物兑换積分</th>
            <th>積分过期时间</th>
            <th>編輯</th>
        </tr>
        </thead>
        <tbody>
        @foreach ($result as $k=>$v)
            <tr>
                <td style="width:150px">
                    {{$v->name}}
                </td>
                <td>
                    {{$v->user_number}}
                </td>
                <td>
                    <img src="{{$v->head_img}}" width="300" height="150">
                </td>
                <td>
                    @foreach($headhunting_commission_level as $vv)
                    {{$vv->rank_name}}&nbsp;<input onchange="edit_rank($(this))" name="user_rank_id_{{$v->id}}" type="radio"
                        value="{{$vv->id}}"  @if($vv->id == $v->user_rank_id) checked @endif>&nbsp;
                    @endforeach
                </td>
                <td>
                    {{$v->nickname??''}}
                </td>
                <td>{{$v->phone}}</td>
                <td>{{$v->total_train_time??''}}</td>
                <td>{{$v->total_integral??''}}</td>
                <td>
                    {{$v->user_goods_integral??''}}</br>
                </td>
                <td>
                    <div class="form-group">

                        <a class="btn btn-primary btn-sm dropdown-toggle" onclick="save_time($(this))"
                           user_id="{{$v->id}}" style="height: 34px;line-height: 23px;" href="javascript:void(0)">保存</a>

                        <div class="col-sm-7">
                            <input type="text" name="expire_time_{{$v->id}}" class="form-control" style="float: left"
                                   id="expire_time_{{$k}}" value="{{$v->expire_time??''}}">
                        </div>

                    </div>
                </td>
                <td style="width:200px">
                    @if(permission('/user_edit', $user['right_list'], $user['get_routes']))
                        <a class="btn btn-primary btn-sm dropdown-toggle" href="/user_edit/{{$v->id}}">編輯
                        </a>&nbsp;
                    @endif
                    @if(permission('/points_record', $user['right_list'], $user['get_routes']))
                        <a class="btn btn-primary btn-sm dropdown-toggle" url="/points_record/{{$v->id}}"
                           onclick="toggle($(this), '100%', '100%',  '{{$v->name??''}}')">積分記錄
                        </a>&nbsp;
                    @endif
                    @if(permission('/user_vip', $user['right_list'], $user['get_routes']))
                        <a class="btn btn-primary btn-sm dropdown-toggle" url="/user_vip/{{$v->id}}"
                           onclick="toggle($(this), '100%', '100%',  '{{$v->name??''}}')">vip
                        </a>
                    @endif
                </td>
            </tr>
        @endforeach
        </tbody>
        {{ $result->appends(Request::except ('page'))->links() }}
    </table>
    {{ $result->appends(Request::except ('page'))->links() }}
</div>
<script>
    var count = "{{count($result)}}";

    for (var i = 0; i < count; i++) {

        laydate.render({
            elem: '#expire_time_' + i,
            min: '', //设定最小日期为当前日期
            max: '2099-06-16 23:59:59', //最大日期
            istime: false,
            istoday: false,
            choose: function (datas) {
                //end.min = datas; //开始日选好后，重置结束日的最小日期
                //end.start = datas //将结束日的初始值设定为开始日
            }
        });

    }


    function save_time(obj) {
        var user_id = obj.attr('user_id');

        var time = $("input[name='expire_time_" + user_id + "']").val();

        var form = new FormData();

        form.append("user_id", user_id);
        form.append("expire_time", time);

        $.ajax({
            type: 'POST',
            url: '/user_update_expire_time',
            dataType: "json",   //返回格式为json
            data: form,
            processData: false,
            contentType: false,
            success: function (data) {

                if (data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        //window.location.reload();
                    });

                } else {
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });

    }

    function edit_rank(obj){
        var name = obj.attr('name');
        var rank_id = obj.val();


        $.ajax({
            url: '/edit_rank',
            data: {
                name: name,
                rank_id: rank_id
            },
            type: 'POST',
            success: function (res) {


            }
        })

    }
</script>
